package echat.future.cn.echat.message.adapter;

import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import echat.future.cn.echat.R;
import echat.future.cn.echat.message.bean.AppointmentBean;
import echat.future.cn.echat.my.weight.CircleImageView;
import lumingweihua.future.cn.baselibgxh.base.MyApplication;
import lumingweihua.future.cn.baselibgxh.utils.CommonUtils;

/**
 * 我的预约
 * Created by JX on 2018/8/13.
 */

public class AppointmentAdapter extends BaseQuickAdapter<AppointmentBean, BaseViewHolder> {

    private double price;

    public AppointmentAdapter(int layoutResId, @Nullable List<AppointmentBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, AppointmentBean item) {
        RequestOptions options = new RequestOptions();
        options.centerCrop()
                .placeholder(R.mipmap.ic_launcher);
        Glide.with(mContext).load(item.getAvatar()).apply(options).into((CircleImageView) helper.getView(R.id.iv_head));
        helper.setText(R.id.tv_name, item.getUsername());
        helper.setText(R.id.tv_jibie, "LV." + item.getLevel());
        helper.setText(R.id.tv_theme, item.getTheme());
        helper.setText(R.id.tv_duration, item.getDuration() + "分钟");

        helper.setText(R.id.tv_wait, "预约时间:" + CommonUtils.timeStamp2Date(item.getAppointment_time()+"","MM-dd HH:mm"));
        helper.setText(R.id.tv_money, (item.getDuration() * item.getPrice()) + "E币");

        helper.addOnClickListener(R.id.tv_delete);
        helper.addOnClickListener(R.id.tv_start);
        if(MyApplication.getInstance().isZhubo){
            helper.getView(R.id.tv_start) .setVisibility(View.VISIBLE);
        }else{
            helper.getView(R.id.tv_start) .setVisibility(View.GONE);
        }
    }

    /**
     * 毫秒转化
     * @param ms
     * @return
     */
    public static String formatTime(long ms) {
        int ss = 1000;
        int mi = ss * 60;
        int hh = mi * 60;
        int dd = hh * 24;

        long day = ms / dd;
        long hour = (ms - day * dd) / hh;
        long minute = (ms - day * dd - hour * hh) / mi;
        long second = (ms - day * dd - hour * hh - minute * mi) / ss;
        long milliSecond = ms - day * dd - hour * hh - minute * mi - second * ss;

        String strDay = day < 10 ? "0" + day : "" + day; //天
        String strHour = hour < 10 ? "0" + hour : "" + hour;//小时
        String strMinute = minute < 10 ? "0" + minute : "" + minute;//分钟
        String strSecond = second < 10 ? "0" + second : "" + second;//秒
        String strMilliSecond = milliSecond < 10 ? "0" + milliSecond : "" + milliSecond;//毫秒
        strMilliSecond = milliSecond < 100 ? "0" + strMilliSecond : "" + strMilliSecond;

        return strMinute + " 分钟 " + strSecond + " 秒";
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}